package com.example.demo.service.equipment;

import com.example.demo.domain.equipment.Budget;
import com.example.demo.domain.equipment.repository.BudgetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BudgetService {
    @Autowired
    private BudgetRepository budgetRepository;
    /**
     * @Description: 获取全部未审批列表
     * @Param:  无
     * @return:  全部未审批列表
     * @Author: wangze
     */
    public List<Budget> getBudget(String planId) {
        return budgetRepository.getAllByPlanId(planId);
    }

    public Budget addbudget(Budget b) {
        return budgetRepository.save(b);
    }

    public Budget getBudgetbyTicketidMatched(Integer id) {
        return budgetRepository.findByTicketId(id);
    }

    public Budget editBudget(Budget b){
        Budget budget=budgetRepository.findByTicketId(b.getTicketId());
        budget.setBudgetItem(b.getBudgetItem());
        budget.setBudgetNum(b.getBudgetNum());
        budget.setRemark(b.getRemark());
        return budgetRepository.save(budget);
    }

    public void deleteBudget(Integer id){
        budgetRepository.deleteById(id);
    }
}
